package com.tpod.taxi;

import tpod.network.HTTPNetworkConfig;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;

import com.tpod.taxi.utils.SysUtils;
import com.tpod.taxi.utils.UIUtils;

public class TaxiApplication extends Application {

	private boolean isNotificaledLostConection = false;
	private boolean isInternetConected = false;
	public static final String HOST_API = "http://api.dzanplay.com/index.php";
	public static final String CITY_API = "http://api.dzanplay.com/";

	@Override
	public void onCreate() {
		super.onCreate();

		// Initialize UIUtils
		UIUtils.init(getApplicationContext());

		// Configuration Network
		HTTPNetworkConfig.ApplicationPackageName = getClass().getPackage()
				.getName();

	}

	public boolean isOnlineMode() {
		return isInternetConected;
	}

	public void updateConnectionMode(Activity activity) {
		isInternetConected = SysUtils.isInternetConected();
		if (isInternetConected) {
			isNotificaledLostConection = false;
		} else {
			if (!isNotificaledLostConection) {
				getDialogLostConection(activity).show();
				isNotificaledLostConection = true;
			}
		}
	}

	private Dialog getDialogLostConection(Activity activity) {
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setTitle(getString(R.string.lost_connection_title));
		builder.setMessage(R.string.lost_connection_message);
		builder.setPositiveButton(getString(R.string.lost_connection_dissmis),
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.dismiss();
					}
				});
		builder.setNegativeButton(getString(R.string.lost_connection_setting),
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						startActivity(new Intent(
								android.provider.Settings.ACTION_WIRELESS_SETTINGS));
					}
				});
		AlertDialog dialog = builder.create();
		return dialog;
	}

}
